package com.yiwei.hdb.view;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.yiwei.hdb.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/3/16 0016.
 */
public class PaySubmitDialog extends android.app.Dialog {


    @BindView(R.id.txt_money)
    TextView txtMoney;
    @BindView(R.id.txt_content)
    TextView txtContent;
    @BindView(R.id.txt_number)
    TextView txtNumber;
    @BindView(R.id.txt_type)
    TextView txtType;
    private static final String WX_APP = "WX_APP";
    private static final String ALI_APP = "ALI_APP";
    private static final String UN_APP = "UN_APP";

    public PaySubmitDialog(Context context) {
        super(context, R.style.mydialog);
        init();
    }

    public PaySubmitDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public PaySubmitDialog setOnSelect(OnSureListener listener) {
        selectListener = listener;
        return this;
    }

    @OnClick({R.id.btn_close, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_close:
                dismiss();
                break;
            case R.id.btn_submit:
                if (selectListener != null) {
                    selectListener.onSure();
                }
                break;
        }
    }

    public void setContent(String money, String type, String content, String number) {
        if (type.equals(WX_APP)) {
            txtType.setText("微信");
        } else if (type.equals(ALI_APP)) {
            txtType.setText("支付宝");
        } else if (type.equals(UN_APP)) {
            txtType.setText("银行卡");
        }

        txtContent.setText(content);
        txtNumber.setText(number);
        txtMoney.setText("￥"+money);

    }


    public interface OnSureListener {
        void onSure();
    }

    private OnSureListener selectListener;

    private void init() {
        Window window = this.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.setWindowAnimations(R.style.mydialog_animation);
        setContentView(R.layout.dialog_pay_submit);
        ButterKnife.bind(this);

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.gravity = Gravity.BOTTOM;
        window.setAttributes(lp);
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        this.setCanceledOnTouchOutside(false);
    }


}
